package org.dromara.comm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.comm.domain.AsLeaveIdle;
import org.dromara.comm.domain.AsLeaveIdleImage;
import org.dromara.comm.domain.AsUserLeaveIdle;
import org.dromara.comm.mapper.AsLeaveIdleImageMapper;
import org.dromara.comm.mapper.AsUserLeaveIdleMapper;
import org.dromara.comm.service.AsLeaveIdleImageService;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.SysUser;
import org.dromara.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 闲置图片业务层
 *
 * @author: 郭伟明
 * @date: 2024-08-05 09:32
 **/
@Service
public class AsLeaveIdleImageServiceImpl extends ServiceImpl<AsLeaveIdleImageMapper, AsLeaveIdleImage> implements AsLeaveIdleImageService {

    @Autowired
    private AsLeaveIdleImageMapper asLeaveIdleImageMapper;

    /**
     * 上传闲置图片
     * @param asLeaveIdleImages
     * @param asLeaveIdle
     */
    @Override
    public List<Integer> insertAsLeaveIdleImages(List<AsLeaveIdleImage> asLeaveIdleImages, AsLeaveIdle asLeaveIdle) {
        List<Integer> ids = new ArrayList<>();

        if (asLeaveIdleImages == null || asLeaveIdle == null) {
            throw new IllegalArgumentException("asLeaveIdleImages或asLeaveIdle不能为空");
        }

        for (AsLeaveIdleImage asLeaveIdleImage : asLeaveIdleImages) {
            AsLeaveIdleImage image = new AsLeaveIdleImage();
            image.setImageId(asLeaveIdle.getId());
            image.setUrl(asLeaveIdleImage.getUrl());
            try {
                asLeaveIdleImageMapper.insert(image);
                ids.add(image.getId());
                System.out.println("Inserted image with ID: " + image.getId() + ", URL: " + image.getUrl());
            } catch (Exception e) {
                System.err.println("Error inserting image with URL: " + image.getUrl());
                e.printStackTrace();
            }
        }

        return ids;
    }




}
